package com.basedefence;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainMenu extends Activity implements AnimationListener
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_menu);
    }
    
    @Override
    public void onResume ()
    {
    	super.onResume();
    	StartIntro ();
    }
    
    public static View m_MenuItemPressed;
    public void StartIntro ()
    {
    	m_MenuItemPressed = null;
    	MenuLogoStartIntro ();
        MenuButtonStartIntro(R.id.btQuickPlay);
        MenuButtonStartIntro(R.id.btExit);
        MenuButtonStartIntro(R.id.btOptions);
        MenuButtonStartIntro(R.id.btHelp);
    }
    
    
    public void MenuLogoStartIntro ()
    {
    	ImageView logo = (ImageView) findViewById(R.id.imageViewLogo);
    	Animation anim = AnimationUtils.loadAnimation(MainMenu.this, R.anim.logo_anim);
    	logo.startAnimation(anim);
    }
    
    public void MenuButtonStartIntro (int id)
    {
    	Button bt = (Button) findViewById(id);
    	bt.setVisibility(Button.VISIBLE);
    	bt.setClickable(true);
    	Animation anim = AnimationUtils.loadAnimation(MainMenu.this, R.anim.bt_intro);
    	anim.setAnimationListener(MainMenu.this);
    	bt.startAnimation(anim);
    }
    
    public void MenuButtonStartOutro (View v)
    {
    	m_MenuItemPressed = v;
    	m_MenuItemPressed.setClickable(false);
    	Animation anim = AnimationUtils.loadAnimation(MainMenu.this, R.anim.bt_outro);
    	anim.setAnimationListener(MainMenu.this);
    	v.startAnimation(anim);
    }
    
    
    public void btQuickPlay_Click(View v)
    {
    	MenuButtonStartOutro(v);
    }
    
    public void btOptions_Click(View v)
    {
    	//MenuButtonStartOutro(v);
    }
    
    public void btHelp_Click(View v)
    {

    }
    
    public void btExit_Click(View v)
    {
    	MenuButtonStartOutro(v);
    }
    
	@Override
	public void onAnimationEnd(Animation animation) 
	{
		// TODO Auto-generated method stub
		if (m_MenuItemPressed == null)
			return;
		
		m_MenuItemPressed.setVisibility(Button.INVISIBLE);
		Class activityClass = null;
		switch (m_MenuItemPressed.getId()) 
		{
			case R.id.btQuickPlay:
				activityClass = BaseDefenceActivity.class;
				break;
	
			case R.id.btExit:
				finish();
				return;
				
			default:
				return;
		}

		Intent i = new Intent(this, activityClass);
        startActivity(i);
	}
	
	@Override
	public void onAnimationRepeat(Animation animation) 
	{
		// TODO Auto-generated method stub
		
	}


	@Override
	public void onAnimationStart(Animation animation) 
	{
		// TODO Auto-generated method stub
		
	}
    
}
